const express = require("express");
const bodyPaer = require("body-parser");
const cookieParser = require("cookie-parser");
const sessions = require("express-session");
const ip = require("ip");
const uuid = require("uuid");
const morgan = require("morgan")
let server = express();


//搭建静态资源服务 (css,image,js)
server.use(express.static("./public"));

//1配置中间件
server.use(morgan("dev"));

server.use(bodyPaer.urlencoded({ extended: false }));
server.use(bodyPaer.json());
//express默认能发送cookie到前端,但是不能接受前端的cookie就要使用cookieParser
server.use(cookieParser('yoho.net'));
server.use(sessions({
    // store:  例外一台服务器的ip地址即可 配合radius 存储 分布式的 session数据,
    name: "yoho.net",
    genid: function () {
        return uuid.v1();
    },
    maxAge: 1000 * 60 * 20,
    resave: true,
    saveUninitialized: true
}));


// sequelize orm 不同sql一样的操作数据库
//2.引入api的路由
server.use("/api", require("./routes/apiRoutes"));



server.listen(8081, function () {
    console.log(`http://${ip.address()}:8081 服务器启动完毕!`);
})




